package van.planifolia.methodref;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/11/4 17:33
 */
public class MethodRef4 {
    public static void main(String[] args) {
        // 我们想要模拟动物类的构造方法引用就需要对照着动物类的构造方法创建一个函数式接口，然后才能演示构造方法引用
//        AnimalFactory animalFactory = ((name, age, address) -> new Animal(name,age,address));
        AnimalFactory<Animal> animalFactory = Animal::new;
        System.out.println(animalFactory.createBean("东北虎", 18, "东北"));
    }
}
/**
 * 定义一个创建Animal类对象的函数式接口
 */
@FunctionalInterface
interface AnimalFactory<T>{
    Animal createBean(String name,Integer age,String address);
}
class Animal{
    private String name;
    private Integer age;
    private String address;

    public Animal(String name, Integer age, String address) {
        this.name = name;
        this.age = age;
        this.address = address;
    }
    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", address='" + address + '\'' +
                '}';
    }
}
